    <template>
    <div class="app-container">
        <uc-table url="admin/role/getPage" name="角色" ref="roleTable" pageable table-border :search-form="searchForm">
            <template slot="searchForm">
                <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
                    <!--搜索输入框-->
                    <el-form-item>
                        <el-input type="text" v-model="searchForm.name" placeholder="请输入角色名" clearable @clear="clearInput()"></el-input>
                    </el-form-item>
                    <!--搜索按钮--新增按钮-->
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
                        <el-button type="success" icon="el-icon-plus" class="filter-item" @click="handleAdd()">新 增</el-button>
                    </el-form-item>
                </el-form>
            </template>
            <template slot="columns">
                <el-table-column prop="name" label="角色名" align="left"></el-table-column>
<!--                <el-table-column prop="code" label="角色编码" align="left" show-overflow-tooltip></el-table-column>-->
                <el-table-column prop="remark" label="角色描述" align="left"></el-table-column>
                <el-table-column label="角色状态" prop="isUse">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" content="点击切换角色可用状态" placement="top">
                            <el-tag class="pointer" @click="handleChangStatus(scope.row)" :type="scope.row.isUse?'success':'danger'">{{scope.row.isUse?"可用":"禁用"}}</el-tag>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column prop="address" label="操作" width="220" align="left"
                                 class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <!--编辑按钮-->
                        <el-button size="mini" icon="el-icon-edit" type="primary" :disabled="scope.row.deleted&&!adminCole" @click="handleEdit(scope.row)">编辑
                        </el-button>
                        <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情
                        </el-button>
                        <el-button size="mini" type="danger" icon="el-icon-delete" :disabled="scope.row.deleted" :loading="deleteLoading"
                                   @click="handleDelete(scope.row)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </template>
        </uc-table>
    </div>
</template>

<script>
import UcTable from "@/components/UcTable/index.vue";
import {deleteInRole, updateInRoleStatus} from "@/api/role";

export default {
    name: "roleList",
    components: {UcTable},
    data() {
        return {
            searchForm: {
            },
            deleteLoading: false
        }
    },
    computed:{
        adminCole(){
            let roleCode = this.$store.getters.roleCode;
            return roleCode=="XT-SUPER"||roleCode=="XT-ADMIN"
        }
    },
    methods: {
        handleSearch() {
            this.$refs.roleTable.getTableData(1)
        },
        handleAdd() {
            this.$router.push("/sys/role/edit")
        },
        handleEdit(val) {
            this.$router.push("/sys/role/edit?ucId=" + val.ucId)
        },
        handleInfo(val){
            this.$router.push("/sys/role/info?ucId="+val.ucId)
        },
        clearInput(){
          //清除输入框
          this.searchForm.name = null
          this.handleSearch()
        },
        //变更角色可用状态
        handleChangStatus(val){
            this.$confirm('您确定要执行变更' + val.name + '这个角色状态吗？', '提醒信息', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let obj = Object.assign({},val)
                obj.isUse = !obj.isUse
                updateInRoleStatus(obj).then(res => {
                    this.$notify.success({
                        title: '成功',
                        message: "变更角色状态成功"
                    })
                    this.handleSearch()
                }).catch(res => {
                    this.$notify.error({
                        title: '失败',
                        message: res.msg
                    })
                })
            })
                    .catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
        },
        handleDelete(val) {
            this.$confirm('您确定要执行删除' + val.name + '这个角色吗？', '提醒信息', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.deleteLoading = true
                deleteInRole(val).then(res => {
                    this.deleteLoading = false
                    this.$notify.success({
                        title: '成功',
                        message: "删除角色成功"
                    })
                    this.handleSearch()
                }).catch(res => {
                    this.deleteLoading = false
                    this.$notify.error({
                        title: '失败',
                        message: res.msg
                    })
                })
            })
                    .catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
        }
    }
}
</script>

<style scoped>

</style>